/*******************************************************************************
 * Copyright (c) 2010, 2010 Xbeam Project and ChenZhiKong.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 *******************************************************************************/
package org.bellusoft.xbeam.framework;

import org.osgi.framework.Constants;

/**
 *
 */
public interface XbeamConstants extends Constants{
	
	/**
	 * Xbeam specific framework properties
	 */
	public final static String Xbeam_Bundle_Start_Level = "xbeam.bundle.startlevel" ; 
	
	public final static String Xbeam_Initial_Bundle_Dir = "xbeam.initial.bundle.dir" ;
	
	public final static String Xbeam_Start_Setting = "xbeam.start.setting" ;
	
	public final static String Xbeam_Initial_Bundle_Config = "xbeam.initial.bundle.config" ; 
	
	public final static String Xbeam_Config = "xbeam.config" ; 
	
	/**
	 * default value of Xbeam specific framework properties   
	 */
	final static int Xbeam_Bundle_Start_Level_Default = 1 ; 
	
	final static String Xbeam_Initial_Bundle_Dir_Default = "bundles" ;
	
	final static String Xbeam_Start_Setting_Default = "DeclaredActive"; 
	
	final static String Xbeam_Initial_Bundle_Config_Default = "config/initialBundles.xml" ;
	
	final static String Xbeam_Config_Default = "config/config.properties" ; 
	
	/**
	 * default value of osgi standard framework properties
	 */
	final static String Osgi_Bundle_Parent_Default = org.osgi.framework.Constants.FRAMEWORK_BUNDLE_PARENT_BOOT ; 
	
	final static String Osgi_Startlevel_Beginning_Default = "1" ;
	
	final static String Osgi_Storage_Default = "xbeamcache" ;
	
	final static String Osgi_Storage_Clean_None = "none" ; 
	
	public enum StorageCleanPolicy {
		none, onFirstInit ; 
		public static StorageCleanPolicy parse(String value){
			if(value==null){
				return none ; 
			}
			if(value.equals(XbeamConstants.Osgi_Storage_Clean_None)){
				return none ; 
			}
			if(value.equals(Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT)){
				return onFirstInit ; 
			}
			throw new IllegalArgumentException(value+" is not a valid value of framework property "+Constants.FRAMEWORK_STORAGE_CLEAN+
					", valid values are [none, onFirstInit]");
		}
	} ; 
	
	public enum AutoStartSetting {
		/**
		 * p4.4.5 
		 */
		stopped, eager, declared ; 
		
		public static AutoStartSetting parse(String value){
			if(value==null){
				return declared ; 
			}
			if(value.equals("declared")){
				return declared ; 
			}
			if(value.equals("eager")){
				return eager ; 
			}
			if(value.equals("stopped")){
				return stopped ; 
			}
			throw new IllegalArgumentException(value+" is not a valid value of framework property "+Constants.FRAMEWORK_STORAGE_CLEAN+
					", valid values are [none, onFirstInit]");
		}
		
	}
	
	public enum BundleParent {
		
		boot, app, ext, framework;

		public static BundleParent parse(String value) {
			if(value==null||value.trim().isEmpty()){
				return boot ; 
			}
			if(value.equals(Constants.FRAMEWORK_BUNDLE_PARENT_BOOT)){
				return boot ; 
			}
			if(value.equals(Constants.FRAMEWORK_BUNDLE_PARENT_APP)){
				return app ; 
			}
			if(value.equals(Constants.FRAMEWORK_BUNDLE_PARENT_EXT)){
				return ext ; 
			}
			if(value.equals(Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK)){
				return framework ; 
			}
			throw new IllegalArgumentException(value+" is not a valid value of framework property "+Constants.FRAMEWORK_BUNDLE_PARENT+
					",valid values are [boot, app, ext, framework]");
		}
	
	}
	
}
